/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.BusinessLogicLayer;

import edu.nii.qlks.DataAccessLayer.MSSQLConnectUnit;
import edu.nii.qlks.DataTransferObject.LoaiPhongInfo;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author MARS_NHO
 */
public class LoaiPhongBLL {
    
    MSSQLConnectUnit _connect;
    ResultSet  _result;
    
    public ArrayList LayDS(String Condition, String OderBy) throws Exception{
        ArrayList vt = new ArrayList();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("LOAIPHONG", Condition, OderBy);
        
        while (_result.next()){
            ArrayList vt_row = new ArrayList();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt_row.add(_result.getString(3));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public ArrayList LayDS(String Condition) throws Exception{
         return LayDS(Condition, null);
    }
    
    public ArrayList LayDS() throws Exception{
        return LayDS(null);
    }
    
    public ArrayList LayDS_LoaiPhong() throws Exception{
        ArrayList vt = new ArrayList();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.LayDS_LoaiPhong();
        int stt = 0;
        while (_result.next()){
            ArrayList vt_row = new ArrayList();
            stt++;
            vt_row.add(stt);
            vt_row.add(_result.getString(2));
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(3));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public String[] LayMaLoaiPhong() throws Exception{
        
        String [] array = new String[10];
        int soItem = 0;
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.LayMaLoaiPhong();
        while (_result.next()){
            array[soItem] = (_result.getString(1));
            soItem++;
        }
        String [] array2 = new String[soItem];
        for (int j = 0; j < soItem; j++) {
                array2[j] = array[j].trim();
        }
        _connect.Close();
        return array2;
    }
    
    public String[] LayTenLoaiPhong() throws Exception{
        
        String [] array = new String[10];
        int soItem = 0;
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.LayMaLoaiPhong();
        while (_result.next()){
            array[soItem] = (_result.getString(2));
            soItem++;
        }
        String [] array2 = new String[soItem];
        for (int j = 0; j < soItem; j++) {
                array2[j] = array[j].trim();
        }
        _connect.Close();
        return array2;
    }
    
    public void Insert(LoaiPhongInfo loaiPhongInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaLoaiPhong", loaiPhongInfo.getMaLoaiPhong());
        map.put("TenLoaiPhong", loaiPhongInfo.getTenLoaiPhong());
        map.put("DonGiaPhong", loaiPhongInfo.getDonGiaPhong());
        _connect.Insert("LOAIPHONG", map);
    }
    
    public void Inserts(HashSet<LoaiPhongInfo> loaiPhongInfos) throws Exception{
        for (LoaiPhongInfo loaiPhongInfo:loaiPhongInfos) {
            this.Insert(loaiPhongInfo);
        }
    }
    
    public void Update(LoaiPhongInfo loaiPhongInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("TenLoaiPhong", loaiPhongInfo.getTenLoaiPhong());
        map.put("DonGiaPhong", loaiPhongInfo.getDonGiaPhong());
        _connect.Update("LOAIPHONG", map, "MaLoaiPhong = '" + loaiPhongInfo.getMaLoaiPhong()+"'");
    }
    
    public void Updates(HashSet<LoaiPhongInfo> loaiPhongInfos) throws Exception{
        for (LoaiPhongInfo loaiPhongInfo:loaiPhongInfos){
            this.Update(loaiPhongInfo);
        }
    }
    
    public void Delete(LoaiPhongInfo loaiPhongInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _connect.Delete("LOAIPHONG", "MaLoaiPhong = '" + loaiPhongInfo.getMaLoaiPhong() +"'");
    }
    
    public void Deletes(HashSet<LoaiPhongInfo> loaiPhongInfos) throws Exception{
         for (LoaiPhongInfo loaiPhongInfo:loaiPhongInfos){
            this.Delete(loaiPhongInfo);
        }
    }
    
    public String TaoMaTuDong(String maGoc, int batDau){
         
        return BusinessLogicAbstract.TaoMaTuDong(maGoc, batDau);
    }
}
